/**
 * 
 */
package com.wubo.sec.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/** URL资源，用于权限拦截
 * @author wubo
 * @CreateDate 2010-7-30
 * @version 1.0.01
 */
@Entity
@Table(name="SEC_URL")
public class UrlResource extends Resource {
	private static final long serialVersionUID = -2498813408448624067L;

	@Column(length=50)
	private String name; //资源名
	
	private Date createTime; //创建时间
	private String createUser; //创建用户
	private Date updateTime; //修改时间
	private String updateUser; //修改用户

	@ManyToOne(targetEntity=Authority.class, fetch=FetchType.LAZY)
	@JoinTable(
		name="SEC_URL_AUTH",
		joinColumns=@JoinColumn(name="URL_REL"),
		inverseJoinColumns=@JoinColumn(name="AUTH_REL")
	)
	private Authority auth; //URL资源对应权限（单向关联）
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getCreateUser() {
		return createUser;
	}

	public void setCreateUser(String createUser) {
		this.createUser = createUser;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(String updateUser) {
		this.updateUser = updateUser;
	}

	public Authority getAuth() {
		return auth;
	}

	public void setAuth(Authority auth) {
		this.auth = auth;
	}

	public int hashCode(){
		return this.code.hashCode() + 32;
	}
	
	public boolean equals(Object obj){
		if(obj == null) return false;
		if(! (obj instanceof UrlResource) ) return false;
		UrlResource resource = (UrlResource) obj;
		
		if(resource.getCode() != null && this.getCode() != null){
			return this.getCode().equals("obj");
		} else {
			return this.getUrl().equals(resource.getUrl());
		}
	}
}
